package utils;

import java.util.Comparator;

public class SortUtil {
    public static void bubblesort(Comparator[] comparators) {
        //外层循环代表排序趟数
        for (int i = 0; i < comparators.length; i++) {
            for (int j = comparators.length - 1; j > i; j--) {
                if(comparators[j-1].compare(comparators[j],comparators[j - 1]) > 0) {
                    Comparator tmp = comparators[j - 1];
                    comparators[j - 1] = comparators[j];
                    comparators[j] = tmp;
                }
            }
        }
    }

    public static void bubblesort(Comparable[] comparables) {
        //外部循环代表排序趟数
        for (int i = 0; i < comparables.length; i++) {
            for (int j = comparables.length - 1; j > i ; j--) {
                if(comparables[j - 1].compareTo(comparables[j]) > 0) {
                    Comparable tmp = comparables[j - 1];
                    comparables[j - 1] =  comparables[j];
                    comparables[j] = tmp;
                }
            }
        }
    }



}


